#include <windows.h>
#include "mywindows.h"

HANDLE handle; //全局变量
//1.初始化句柄
void initHandle()
{
    handle = GetStdHandle(STD_OUTPUT_HANDLE);
}

//2.设置标题
void setTitle(char title[40])
{
    SetConsoleTitleA(title);
}

//3.设置位置
void setPosition(int x,int y)
{
    COORD coord = {x*2,y};
    SetConsoleCursorPosition(handle,coord);
}
void setPos(int x,int y)
{
    setPosition(x,y);
}

//4.设置颜色
void setColor(int color)
{
    SetConsoleTextAttribute(handle,color);
}
void setText(int color)
{
    setColor(color);
}

//5.设置光标是否可见
void setCursorVisible(int flag)
{
    CONSOLE_CURSOR_INFO info;
    info.bVisible = flag;
    info.dwSize = 100;
    SetConsoleCursorInfo(handle,&info);
}

//6.设置窗口大小
void setWindowSize(int w,int h)
{
    COORD coord = {w,h};
    SetConsoleScreenBufferSize(handle,coord);
    SMALL_RECT rect = {0,0,w-1,h-1};
    SetConsoleWindowInfo(handle,1,&rect);
}

//7.初始化窗口
void initWindows()
{
    initHandle();//初始化句柄
    setCursorVisible(0);//设置光标不可用
    setWindowSize(100,30);//设置窗口大小
    setTitle("贪吃蛇游戏-v1.0");//设置窗口标题
}
